﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AssettDatabase.BLL;

namespace AssettDatabase
{
    public partial class Form_Sel_Customer : Form
    {
        public string retCustomer_ID { get; set; } 
        public Form_Sel_Customer()
        {
            InitializeComponent();
        }

        private void Form_Sel_Customer_Load(object sender, EventArgs e)
        {
            BLL.Customer bllCustomer = new BLL.Customer();
            gridCustomer.DataSource = bllCustomer.GetCustomers();
        }

        private void gridCustomer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                this.retCustomer_ID = gridCustomer.Rows[e.RowIndex].Cells["Customer_ID"].Value.ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void TB_CustomerName_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void TB_CustomerName_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void TB_CustomerName_KeyUp(object sender, KeyEventArgs e)
        {
            BLL.Customer bllCustomer = new BLL.Customer();
            List<VO.Customer> filterData = new List<VO.Customer>();
            if (TB_CustomerName.Text.Length == 0)
                filterData = bllCustomer.GetCustomers();
            else
                filterData = (from c in bllCustomer.GetCustomers() where c.Customer_Name.ToLower().Contains(TB_CustomerName.Text.ToLower()) select c).ToList();

            gridCustomer.DataSource = filterData;
        }
    }
}
